package cn.pegasus.teamwork.util;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import cn.pegasus.teamwork.sysconfig.entity.SysMessagePush;

public class MseeageUtil {

	
public static Map<String,List<String>> getMessagePushByIosAndAndroid(List<SysMessagePush> list){
		
		Map<String,List<String>> map = new HashMap<String, List<String>>();
		List<String> androidList = null;
		List<String> iosList = null;
		for (SysMessagePush sysMessagePush : list) {
			if(sysMessagePush.getEquipmentId()!=null&&!"".equals(sysMessagePush.getEquipmentId())&&sysMessagePush.getCurrType()==1){//设备ID不为null
				if(sysMessagePush.getEquipmentType()==0){ //Android
					if(androidList == null){
						androidList = new ArrayList<>();
					}
					androidList.add(sysMessagePush.getEquipmentId());
				}else{//IOS
					if(iosList == null){
						iosList = new ArrayList<>();
					}
					iosList.add(sysMessagePush.getEquipmentId());
				}
			}
		}
		map.put("android", androidList);
		map.put("ios", iosList);
		return map;
	}


	public static InputStream getClassNameByJar() {
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		URL url = loader.getResource("izcProDevTest.p12");
		String jarPath = url.getPath().replaceAll("\\/", "\\" + File.separator);
		
	    String[] jarInfo = jarPath.split("!");
	    String jarFilePath = jarInfo[0].substring(jarInfo[0].indexOf(File.separator));
		try {
		    JarFile jarFile = new JarFile(jarFilePath);
		    Enumeration<JarEntry> entrys = jarFile.entries();
		    while (entrys.hasMoreElements()) {
		        JarEntry jarEntry = entrys.nextElement();
		        String entryName = jarEntry.getName();
		        if (entryName.endsWith(".p12")) {
		//                String entryNameReplace = entryName.replaceAll("\\/", "\\" + File.separator);
		//                System.out.println(jarEntry.getMethod());
		//                myClassName.add(entryNameReplace);
		            	InputStream is = jarFile.getInputStream(jarEntry);
		            	return is;
		            }
		     }
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
		  return null;
	}
	
	
	public static void main(String[] args) {
		String os = System.getProperty("os.name");  
		if(os.toLowerCase().startsWith("win")){  
		  System.out.println(os + " can't gunzip");  
		}  
	}
	
}
